﻿<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="content-type" 
				content="text/html;charset=utf-8" />

		<title>BORDACHKA 0.01</title>
		<link rel="stylesheet" src="style.css"/>
	</head>
	<body>
		<?php
			require_once('fw/sqllib.php');
			
			$board = htmlentities(mysql_escape_string($_GET['board']));

			if(!$board)
				echo '<meta http-equiv="refresh" content="0; url=/mainpage.php"/>';

			//fetching boards
			$db->select('boards', null, array( 'hidden' => '=0' ));
			$boards = $db->query();
			
			//fetching threads
			$db->select('posts',  null, array( 
						'isop'  => '=1 AND ',
						'board' => "='$board'"
			),'bump DESC');

			$threads = $db->query();
		?>

		<h1><a href="/">БОРДА-БОРДАЧКА</a></h1>

		<div class='boardlist'>
			<?php foreach($boards as $brd): ?>
				/<a href="/<?=$brd['short']?>" title="<?=$brd['name']?>">
					<?=$brd['short'];?>
				</a>/
			<?php endforeach; ?>
		</div>

		<form class='postarea' action='/post.php' method='post' enctype='multipart/form-data'>
			<input type="hidden" name="thread" value="1"/>
			<input type="hidden" name="board" value="<?=$board?>"/>

			<p>Тема: <input name="title" /></p>
			<p>Имя: <input name="name" /></p>
			<p>Текст: <p><textarea name="text"></textarea></p></p>
			<p>Изображение: <input type="file" name="picture" /></p>
			<button>Отправить</button>
		</form>
		
		<hr/>

		<?php foreach($threads as $thread): ?>
			<?php 
				$id = $thread['id'];
				$postcount = $thread['replies'];
			?>	
			<div class='thread' id="<?=$id?>">
				<p class='header'>
					<span class='id'>
						#<?=$thread['id']?>
					</span>
					<span class='title'>
						<?=$thread['title']?>
					</span>
					<span class='name'>
						<?=$thread['name']?>
					</span>
					<span class='date'>
						<?=$thread['date']?>
					</span>
					<span class='answers'>
						Ответов: <?=$postcount?>
					</span>
				</p>
				
				<?if($thread['pic']):?>
					<?php
						$thread['thumb'] = explode('.',$thread['pic']);
						$thread['thumb'] = $thread['thumb'][0].'.png';
					?>
					<a href="pics/<?=$thread['pic']?>">
						<img src="pics/s/<?=$thread['thumb']?>" />
					</a>
				<?endif;?>

				<p class='text'>
					<?=$thread['text']?>
				</p>
				<p class='footer'>
					<a href='/<?=$board?>/thread/<?=$id?>'>Ответить</a>
				</p>
			</div>
			<hr/>
		<?php endforeach; ?>
	</body>
</html> 
